import { Component } from '@angular/core';
import { NavParams, NavController } from 'ionic-angular';

import { StorageService } from '../../providers/StorageService';
import { SettlementService } from '../../providers/SettlementService';

import { SettlementDetailPage } from '../settlementDetail/settlementDetail';
import { SettlementPage } from "../settlement/settlement";

@Component({
  selector: 'page-historyDetail',
  templateUrl: 'historyDetail.html',
  providers: [SettlementService]
})
export class HistoryDetailPage {
  user_info: any;
  user_id: number;
  room: any;
  build_address: string;
  room_name: string;
  check_in_id: number;
  room_id: number;
  settlements: any;
  settlementPage = 1;

  constructor(
    navParams: NavParams,
    private navCtrl: NavController,
    private storageService: StorageService,
    private settlementService: SettlementService
  ) {
    this.user_info = this.storageService.read('UserInfo');
    this.user_id = this.user_info.user_id;

    this.room = this.storageService.read('RoomInfo');
    this.room_id = this.room.room_id;
    this.room_name = this.room.room_name;
    this.build_address = this.room.build_address;

    this.check_in_id = navParams.get('check_in_id');

    this.settlementService.getList({'user_id': this.user_id, 'room_id': this.room_id, 'check_in_id': this.check_in_id, 'page': this.settlementPage}).then(data => {
      if (data.status == 200) {
        this.settlements = data.settlement;
        this.settlementPage++;
      }
    });
  }

  registerView(settlement) {
    this.navCtrl.push(SettlementDetailPage, {'settlement_id': settlement.settlement_id});
  }

  registerEdit(settlement) {
    this.navCtrl.push(SettlementPage, { 'settlement_id': settlement.settlement_id, 'check_in_id': this.check_in_id });
  }
}
